// request/request.js.js
// let https ="https://192.168.0.1:8080"//生产
// const https ="https://hospital.fanchenjiuluo.com"//测试
const https ="https://nange.shop"//测试


const AjaxPost = (url,params,callback)=>{
  // wx.showLoading({})
  wx.request({
    url: https + url, //仅为示例，并非真实的接口地址
    data: params,
    method:'POST',
    dataType: 'json',
    responseType: 'text',
    header: {
      'content-type': 'application/json;charset=UTF-8', // 默认值
      "cache-control": "no-cache"
    },
    success:(res)=>{
      // wx.hideLoading();  //请求成功后加载动画结束
      return typeof callback == "function"&& callback(res.data)
    },
    fail:(err)=>{
      return typeof callback == "function"&& callback(err)
    }
  })
}
//GET请求
const AjaxGet = (url,callback)=>{
  wx.showLoading({})
  wx.request({
    url: https + url, //仅为示例，并非真实的接口地址
    // data: params,
    method:'GET',
    dataType: 'json',
    responseType: 'text',
    header: {
      'content-type': 'application/json;charset=UTF-8', // 默认值
      "cache-control": "no-cache"
    },
    success:(res)=>{
      wx.hideLoading();  //请求成功后加载动画结束
      return typeof callback == "function"&& callback(res.data)
    },
    fail:(err)=>{
      wx.hideLoading();  
      wx.showModal({
        title: '网络错误',
        content: '网络出错，请刷新重试',
        showCancel: false
      })               
      return typeof callback == "function"&& callback(err)
    }
  })
}
module.exports = {
  AjaxPost,
  AjaxGet
}